home *** CD-ROM | disk | FTP | other *** search
/ Directorty Opus 5 - Magellan 2 / Opus 5 - Magellan 2.iso / Extras / D51_NUSource / Source / Routines / NIB.s < prev    next >
Text File  |  1995-09-26  |  20KB  |  480 lines

  1. ***************************************************************************************
  2. * Nudel-Info-Block (NIB) Routines                              *
  3. ***************************************************************************************
  4.  
  5. ;=====================================================================================;
  6. ; NudelInfoBlock Subroutines.                                  ;
  7. ;=====================================================================================;
  8. ;NIBR_ALLOCATE    ; (De)Allocate memory
  9. ;NIBR_OPEN    ; DOS/(Open|Close)
  10. ;NIBR_LOCK    ; DOS/(Un)Lock
  11. ;NIBR_EXAMINE    ; DOS/(Un)Examine (allocates FileInfoBlock)
  12. ;NIBR_NREAD    ; Read a file into memory (creates and fills in a new NIB).
  13. ;    Include    ASM:Source/Routines/NIB.s
  14.  
  15.  
  16. ;=====================================================================================;
  17. ; NUDEL-INFO-BLOCK STRUCTURE                                  ;
  18. ;=====================================================================================;
  19. ;See ASM:Include/Constants.i
  20.  
  21.  
  22. ***********************************************************************= 12-Aug-1995 =*
  23. * Create a new NIB                                      *
  24. *=====================================================================================*
  25. *  Inputs: Various NIB pointers.                              *
  26. * Outputs: Various NIB pointers updated.                          *
  27. * Active_NIB(a5) = Address of new NIB.                              *
  28. *   Notes: Assume all registers apart from d0/a0 destroyed.                  *
  29. *          Program will abort if allocation fails.                      *
  30. ***************************************************************************************
  31. Create_NIB
  32.     Moveq    #NIB_SizeOf,d0            Size of NIB structure.
  33.     Lea    IDS_FileName(pc),a0        -._ Set pseudo-filename.
  34.     Move.l    a0,NIB_NameAdrs+FakeNIB(a5)    -'  in fake NIB.
  35.     Bsr    LeoAllocPooled            -.
  36.     Tst.l    d0                 |- Get mem, quit on failure.
  37.     Beq_ErrorE    ErrAct_AllocMem(pc),FakeNIB_Adrs(a5)
  38.     Sub.l    d1,d1                -.
  39.     Move.l    d0,a0                 |
  40.     Move.l    d1,NIB_Next(a0)             |
  41. ;;;;;;;    Move.l    d1,NIB_Previous(a0)         |
  42.     Move.l    d1,NIB_MemSize(a0)         |_ Initialise
  43.     Move.l    d1,NIB_MemAdrs(a0)         |  the structure.
  44.     Move.l    d1,NIB_NameAdrs(a0)         |
  45.     Move.l    d1,NIB_Handle(a0)         |
  46.     Move.l    d1,NIB_Lock(a0)             |
  47.     Move.l    d1,NIB_FIB(a0)            -'
  48.     Move.l    Last_NIB(a5),NIB_Previous(a0)    Pointer to old last NIB.
  49.     Bne.s    CNIB_S1                -._ If null, this
  50.     Move.l    a0,Base_NIB(a5)            -'  is the base NIB.
  51.     Bra.s    CNIB_S2
  52. CNIB_S1    Move.l    NIB_Previous(a0),a1        -._ Update "next" pointer
  53.     Move.l    a0,NIB_Next(a1)            -'  in previous NIB.
  54. CNIB_S2    Move.l    a0,Last_NIB(a5)            This is now the last NIB.
  55.     Move.l    a0,Active_NIB(a5)        Set Active NIB.
  56.     RTS
  57.  
  58. IDS_FileName
  59.     Dc.b    "internal data structure"
  60.     Even
  61.  
  62.  
  63. ***********************************************************************= 11-Aug-1995 =*
  64. * Delete ALL NIBs                                      *
  65. *=====================================================================================*
  66. *   Notes: Assume all registers apart are destroyed.                      *
  67. ***************************************************************************************
  68. NIBs_DeleteAll
  69.     Bra.s    NIBs_DelStart
  70. NIBs_DelMore
  71.     Move.l    d0,Active_NIB(a5)        ...make it "Active" for Deletion.
  72.     Bsr.s    Delete_NIB            Delete this NIB, update Ptrs.
  73. NIBs_DelStart
  74.     Move.l    Base_NIB(a5),d0            Get current Base NIB...
  75.     Bne.s    NIBs_DelMore            If all Freed, routine completed.
  76.     RTS
  77.  
  78.  
  79. ***********************************************************************= 12-Aug-1995 =*
  80. * Delete a NIB                                          *
  81. *=====================================================================================*
  82. *  Inputs: Active_NIB(a5) = Pointer to NIB to delete.                      *
  83. * Outputs: Various NIB pointers updated.                          *
  84. *          Active_NIB(a5) = NULL                              *
  85. *   Notes: Assume all registers apart are destroyed.                      *
  86. *          If extra memory was allocated for the filename, _you_ must be free it.     *
  87. *          (You should allocate this mem as a NIB and thus have it auto-freed)        *
  88. ***************************************************************************************
  89. Delete_NIB
  90.     Tst.l    Active_NIB(a5)            -.
  91.     Bne.s    Delete_NIB_Skip             |- No NIB? Skip routine.
  92.     RTS                    -'
  93. Delete_NIB_Skip
  94.     IFD    NIBR_ALLOCATE            -.
  95.     Bsr    Deallocate_NIB             |- Free memory if allocated.
  96.     ENDC                    -'
  97.     IFD    NIBR_OPEN            -.
  98.     Bsr    Close_NIB             |- Close if openned.
  99.     ENDC                    -'
  100.     IFD    NIBR_LOCK            -.
  101.     Bsr    UnLock_NIB             |- Unlock if locked.
  102.     ENDC                    -'
  103.     IFD    NIBR_EXAMINE            -.
  104.     Bsr    UnExamine_NIB             |- Free FileInfoBlock if allocated.
  105.     ENDC                    -'
  106.     Move.l    Active_NIB(a5),a1
  107.     Move.l    #0,Active_NIB(a5)        No active NIB anymore.
  108.  
  109.     Move.l    NIB_Previous(a1),a0        a0 = Previous NIB
  110. ;;;;;;;                        a1 = This NIB
  111.     Move.l    NIB_Next(a1),a2            a2 = Next NIB
  112.  
  113. Delete_NIB_DeLink
  114.     Tst.l    NIB_Previous(a1)        A previous NIB?
  115.     Beq.s    Delete_NIB_NoPrev        If not, jump
  116. Delete_NIB_Prev
  117.     Tst.l    NIB_Next(a1)            A next NIB?
  118.     Beq.s    Delete_NIB_Prev_NoNext        If not, jump
  119.  
  120. Delete_NIB_Prev_Next
  121.     Move.l    a2,NIB_Next(a0)
  122.     Move.l    a0,NIB_Previous(a2)
  123.     Bra.s    Delete_NIB_DeLinked
  124.  
  125. Delete_NIB_Prev_NoNext
  126.     Move.l    a0,Last_NIB(a5)
  127.     Move.l    a2,NIB_Next(a0)            (a2 = 0)
  128.     Bra.s    Delete_NIB_DeLinked
  129.  
  130.  
  131. Delete_NIB_NoPrev
  132.     Tst.l    NIB_Next(a1)            A next NIB?
  133.     Beq.s    Delete_NIB_NoPrev_NoNext    If not, jump
  134.  
  135. Delete_NIB_NoPrev_Next
  136.     Move.l    a2,Base_NIB(a5)
  137.     Move.l    a0,NIB_Previous(a2)        (a0 = 0)
  138.     Bra.s    Delete_NIB_DeLinked
  139.  
  140. Delete_NIB_NoPrev_NoNext
  141.     Move.l    a0,Base_NIB(a5)            (a0 = 0)
  142.     Move.l    a0,Last_NIB(a5)            (a0 = 0)
  143. ;;;;;;;    Bra.s    Delete_NIB_DeLinked
  144. Delete_NIB_DeLinked
  145.  
  146. ;;;;;;;    Move.l    a1,a1                -.
  147.     Moveq    #NIB_SizeOf,d0             |- Free the NIB itself.
  148.     Bra    LeoFreePooled            -'
  149. ;;;;;;;    RTS for us.
  150.  
  151.  
  152.     IFD    NIBR_ALLOCATE
  153. ***********************************************************************= 22-Jul-1995 =*
  154. * Allocate for a NIB                                      *
  155. *=====================================================================================*
  156. *  Inputs: Active_NIB(a5)/NIB_MemSize = Size of memory to be allocated.              *
  157. * Outputs: Active_NIB(a5)/NIB_MemAdrs = Address of allocated memory.              *
  158. *   Notes: Assume all registers apart are destroyed.                      *
  159. *          Program will abort if allocation fails.                      *
  160. ***************************************************************************************
  161. Allocate_NIB
  162.     Move.l    Active_NIB(a5),a0
  163.     Tst.l    NIB_MemAdrs(a0)            -._ Internal error if NIB already
  164.     Bne    Internal            -'  has memory allocated.
  165.     Move.l    NIB_MemSize(a0),d0        Size of allocation to d0.
  166. ;;;;;;;    Tst.l    d0                -._ If zero bytes specified,
  167.     Beq    Internal            -'  internal error.
  168.     Bsr    LeoAllocPooled            -.
  169.     Tst.l    d0                 |- Get mem, quit on failure.
  170.     Beq_ErrorE    ErrAct_AllocMem(pc),Active_NIB(a5)
  171.     Move.l    Active_NIB(a5),a0
  172.     Move.l    d0,NIB_MemAdrs(a0)        Store address in NIB.
  173.     RTS
  174.  
  175. ***********************************************************************= 22-Jul-1995 =*
  176. * Deallocate for a NIB                                      *
  177. *=====================================================================================*
  178. *  Inputs: Active_NIB(a5)/NIB_MemSize = Size of memory to be allocated.              *
  179. *          Active_NIB(a5)/NIB_MemAdrs = Address of allocated memory.              *
  180. * Outputs: Active_NIB(a5)/NIB_MemSize = Null.                          *
  181. *          Active_NIB(a5)/NIB_MemAdrs = Null.                          *
  182. *   Notes: Assume all registers apart are destroyed.                      *
  183. ***************************************************************************************
  184. Deallocate_NIB
  185.     Move.l    Active_NIB(a5),a0
  186.     Move.l    NIB_MemSize(a0),d0        -.
  187. ;;;;;;;    Tst.l    d0                 |
  188.     Beq.s    Deallocate_NIB_Skip         |_ Skip if memory
  189.     Move.l    NIB_MemAdrs(a0),d1         |  not allocated.
  190. ;;;;;;;    Tst.l    d1                 |
  191.     Beq.s    Deallocate_NIB_Skip        -'
  192.     Move.l    d1,a1
  193.     Bra    LeoFreePooled            Free memory.
  194. ;;;;;;;    RTS for us.
  195. Deallocate_NIB_Skip
  196.     RTS
  197.     ENDC
  198.  
  199.  
  200.     IFD    NIBR_OPEN
  201. ***********************************************************************= 26-Sep-1995 =*
  202. * Open for a NIB                                      *
  203. *=====================================================================================*
  204. *  Inputs: Active_NIB(a5)/NIB_NameAdrs = Address of null-term filename to open.          *
  205. *          d2 = #Mode_Old or #Mode_New                              *
  206. *          d7 = Temp storage.
  207. * Outputs: Active_NIB(a5)/NIB_Handle = Handle of opened file.                  *
  208. *          d0 = Null if failure.                              *
  209. *   Notes: Assume all registers apart are destroyed.                      *
  210. *          _You_ must handle error (d0 = #0) yourself.                      *
  211. ***************************************************************************************
  212. Open_NIB
  213.     Move.w    #3,d7            Maximum number of 3 retries.
  214.     Move.l    Active_NIB(a5),a0    -.
  215.     Tst.l    NIB_Handle(a0)         |- Internal error if NIB already open.
  216.     Bne    Internal        -'
  217. Open_NIB_Retry
  218.     Move.l    Active_NIB(a5),a0
  219.     Move.l    NIB_NameAdrs(a0),d1    -.
  220. ;;;;;;;    Tst.l    d1             |- Error if no filename to open.
  221.     Beq    Internal        -'
  222. ;;;;;;;    Move.l    d1,d1            NameAdrs into d1.
  223. ;;;;;;;    Move.l    d2,d2            Mode into d2.
  224.     Movem.l    d2/d7,-(SP)        Preserve mode & nº retries.
  225.     N_CallDOS    Open        Open file.
  226.     Movem.l    (SP)+,d2/d7        Restore mode & nº retries.
  227.  
  228. ;;;;;;;    Note: The only error handled is File-in-use, the calling routine MUST CHECK d0.
  229.     Tst.l    d0            Check for error
  230.     Bne.s    Open_NIB_InUseSkip    -._ If max retries done,
  231.     DBra    d7,Open_NIB_InUse    -'  pass it through.
  232. Open_NIB_InUse_MaxTries
  233.     Moveq    #0,d0
  234. Open_NIB_InUseSkip
  235.     Move.l    Active_NIB(a5),a0
  236.     Move.l    d0,NIB_Handle(a0)    Store filehandle.
  237.     RTS
  238. ;-------------------------------------------------------------------------------------;
  239. Open_NIB_InUse
  240.     Movem.l    d2/d7,-(SP)        Preserve mode & nº retries.
  241.     N_CallDOS    IoErr        Get error return code into d0
  242.     Movem.l    (SP)+,d2/d7        Restore mode & nº retries.
  243.     Cmpi.l    #ERROR_OBJECT_IN_USE,d0    -._ If it's any error other than "in use",
  244.     Bne.s    Open_NIB_InUse_MaxTries    -'  drop it through to the calling routine.
  245.     Movem.l    d2/d7,-(SP)        Preserve mode & nº retries.
  246.     Move.l    #250,d1            -._ Wait
  247.     N_CallDOS    Delay        -'  5 Secs.
  248.     Movem.l    (SP)+,d2/d7        Restore mode & nº retries.
  249.     Bra.s    Open_NIB_Retry
  250.  
  251. ***********************************************************************= 22-Jul-1995 =*
  252. * Close for a NIB                                      *
  253. *=====================================================================================*
  254. *  Inputs: Active_NIB(a5)/NIB_Handle = Handle of opened file.                  *
  255. * Outputs: Active_NIB(a5)/NIB_Handle = Null.                          *
  256. *   Notes: Assume all registers are destroyed.                          *
  257. *          Errors are handled automatically (jump to error routine).              *
  258. ***************************************************************************************
  259. Close_NIB
  260.     Move.l    Active_NIB(a5),a0        a0 = active NIB.
  261.     Move.l    NIB_Handle(a0),d1        Handle to d1.
  262.     Move.l    #0,NIB_Handle(a0)        Mark as closed (MUST be before ErrorE).
  263.     Tst.l    d1                -._ Skip if handle
  264.     Beq.s    Close_NIB_Skip            -'   not open.
  265.     N_CallDOS    Close            Close the file.
  266.     Tst.l    d0                -._ If error, it's fatal.
  267.     Beq_ErrorE    ErrAct_Close(pc),Active_NIB(a5)
  268. Close_NIB_Skip
  269.     RTS
  270. ErrAct_Close
  271.     Dc.b    "Could not close ",0
  272.     Even
  273.     ENDC
  274.  
  275.  
  276.     IFD    NIBR_LOCK
  277. ***********************************************************************= 26-Sep-1995 =*
  278. * Lock for a NIB                                      *
  279. *=====================================================================================*
  280. *  Inputs: Active_NIB(a5)/NIB_NameAdrs = Address of null-term filename to lock.          *
  281. *          d2 = #ACCESS_READ, or #ACCESS_WRITE                          *
  282. *          d7 = Temp storage.
  283. * Outputs: Active_NIB(a5)/NIB_Lock = Lock of locked object.                  *
  284. *          d0 = Null if failure.                              *
  285. *   Notes: Assume all registers are destroyed.                          *
  286. *          _You_ must handle error (d0 = #0) yourself.                      *
  287. ***************************************************************************************
  288. Lock_NIB
  289.     Move.w    #3,d7            Maximum number of 3 retries.
  290.     Move.l    Active_NIB(a5),a0    -.
  291.     Tst.l    NIB_Lock(a0)         |- Internal error if NIB already locked.
  292.     Bne    Internal        -'
  293. Lock_NIB_Retry
  294.     Move.l    Active_NIB(a5),a0
  295.     Move.l    NIB_NameAdrs(a0),d1        -.
  296. ;;;;;;;    Tst.l    d1                 |- Error if no filename to lock.
  297.     Beq    Internal            -'
  298. ;;;;;;;    Move.l    d1,d1                NameAdrs into d1.
  299. ;;;;;;;    Move.l    d2,d2                Mode into d2.
  300.     Movem.l    d2/d7,-(SP)        Preserve mode & nº retries.
  301.     N_CallDOS    Lock            Lock the object.
  302.     Movem.l    (SP)+,d2/d7        Restore mode & nº retries.
  303.  
  304. ;;;;;;;    Note: The only error handled is File-in-use, the calling routine MUST CHECK d0.
  305.     Tst.l    d0            Check for error
  306.     Bne.s    Lock_NIB_InUseSkip    -._ If max retries done,
  307.     DBra    d7,Lock_NIB_InUse    -'  pass it through.
  308. Lock_NIB_InUse_MaxTries
  309.     Moveq    #0,d0
  310. Lock_NIB_InUseSkip
  311.     Move.l    Active_NIB(a5),a0
  312.     Move.l    d0,NIB_Lock(a0)        Store lock.
  313.     RTS
  314.  
  315. Lock_NIB_InUse
  316.     Movem.l    d2/d7,-(SP)        Preserve mode & nº retries.
  317.     N_CallDOS    IoErr        Get error return code into d0
  318.     Movem.l    (SP)+,d2/d7        Restore mode & nº retries.
  319.     Cmpi.l    #ERROR_OBJECT_IN_USE,d0    -._ If it's any error other than "in use",
  320.     Bne.s    Lock_NIB_InUse_MaxTries    -'  drop it through to the calling routine.
  321.     Movem.l    d2/d7,-(SP)        Preserve mode & nº retries.
  322.     Move.l    #250,d1            -._ Wait
  323.     N_CallDOS    Delay        -'  5 Secs.
  324.     Movem.l    (SP)+,d2/d7        Restore mode & nº retries.
  325.     Bra.s    Lock_NIB_Retry
  326.  
  327. ErrAct_Lock
  328.     Dc.b    "Could not lock ",0
  329.     Even
  330.  
  331. ***********************************************************************= 12-Aug-1995 =*
  332. * UnLock for a NIB                                      *
  333. *=====================================================================================*
  334. *  Inputs: Active_NIB(a5)/NIB_Lock = Lock of locked object.                  *
  335. * Outputs: Active_NIB(a5)/NIB_Lock = Null.                          *
  336. *   Notes: Assume all registers are destroyed.                          *
  337. ***************************************************************************************
  338. UnLock_NIB
  339.     Move.l    Active_NIB(a5),a0        a0 = active NIB.
  340.     Move.l    NIB_Lock(a0),d1            Lock to d1
  341.     Move.l    #0,NIB_Lock(a0)            Mark as unlocked (MUST be before ErrE).
  342.     Tst.l    d1                -._ Skip if object
  343.     Beq.s    UnLock_NIB_Skip            -'  not locked.
  344.     N_CallDOS    UnLock            UnLock the object.
  345. UnLock_NIB_Skip
  346.     RTS
  347.     ENDC
  348.  
  349.  
  350.     IFD    NIBR_EXAMINE
  351. ***********************************************************************= 26-Sep-1995 =*
  352. * Examine for a NIB                                      *
  353. *=====================================================================================*
  354. *  Inputs: Active_NIB(a5)/NIB_Lock = Lock of locked object.                  *
  355. * Outputs: Active_NIB(a5)/NIB_FIB = Pointer to filled in FileInfoBlock.              *
  356. *   Notes: Assume all registers are destroyed.                          *
  357. *     : Errors are handled automatically by this routine.                  *
  358. ***************************************************************************************
  359. Examine_NIB
  360.     Move.l    Active_NIB(a5),a0    -.
  361.     Tst.l    NIB_FIB(a0)         |- Internal error if NIB already examined.
  362.     Bne    Internal        -'
  363.  
  364.     Lea    IDS_FileName(pc),a0        -._ Set pseudo-filename in fake NIB
  365.     Move.l    a0,NIB_NameAdrs+FakeNIB(a5)    -'  to "internal data structure".
  366.  
  367.     Moveq    #DOS_FIB,d1        Want to Allocate a FileInfoBlock.
  368.     Moveq    #0,d2            No tags.
  369.     N_CallDOS    AllocDosObject    Allocate it.
  370.     Move.l    Active_NIB(a5),a0    -._ Store pointer to
  371.     Move.l    d0,NIB_FIB(a0)        -'  the FileInfoBlock.
  372.     Beq_ErrorE    ErrAct_AllocMem(pc),FakeNIB_Adrs(a5)
  373.  
  374. ;;;;;;;    Move.l    Active_NIB(a5),a0
  375.     Move.l    NIB_Lock(a0),d1        File lock for Examine()
  376.     Move.l    d0,d2            FileInfoBlock for Examine()
  377.     N_CallDOS    Examine        Examine the file.
  378.     Tst.l    d0
  379.     Beq_ErrorE    ErrAct_Examine(pc),Active_NIB(a5)
  380.     RTS
  381.  
  382. ErrAct_Examine
  383.     Dc.b    "Could not examine ",0
  384.     Even
  385.  
  386. ***********************************************************************= 26-Sep-1995 =*
  387. * UnExamine for a NIB (Frees the FileInfoBlock)                          *
  388. *=====================================================================================*
  389. *  Inputs: Active_NIB(a5)/NIB_FIB = Allocated FileInfoBlock.                  *
  390. * Outputs: Active_NIB(a5)/NIB_FIB = NULL (FileInfoBlock is freed).              *
  391. *   Notes: Assume all registers are destroyed.                          *
  392. ***************************************************************************************
  393. UnExamine_NIB
  394.     Move.l    Active_NIB(a5),a0    -.
  395.     Move.l    NIB_FIB(a0),d2         |_ Skip routine if FIB
  396.     Bne.s    UnExamine_NIB_DoIt     |  hasn't been allocated.
  397.     RTS                -'
  398. UnExamine_NIB_DoIt
  399.     Moveq    #DOS_FIB,d1        Want to Free a FileInfoBlock.
  400. ;;;;;;;    Move.l    d2,d2            Pointer to FIB to be freed.
  401.     N_JumpDOS    FreeDosObject    Free it.
  402. ;;;;;;;    RTS for us.
  403.     ENDC
  404.  
  405.  
  406.     IFD    NIBR_NREAD
  407. ***********************************************************************= 26-Sep-1995 =*
  408. * NRead_NIB: Reads a file into memory, creating and filling in a new NIB.          *
  409. *=====================================================================================*
  410. *  Inputs: a1 - Pointer to filename to read into memory.                  *
  411. * Outputs: d0 - Boolean success.                              *
  412. *       On failure ONLY: The given filename is put into FakeNIB for you.          *
  413. *       Active_NIB(a5) - Pointer to the new NIB for the file.              *
  414. *       Active_NIB(a5)/NIB_FIB - Pointer to filled-in FileInfoBlock for file.      *
  415. *       Active_NIB(a5)/NIB_MemSize - Size of memory allocated (equal to filesize)  *
  416. *       Active_NIB(a5)/NIB_MemAdrs - Pointer to memory containing the file.          *
  417. *   Notes: Failure will only occur if a DOS routine fails, so Ioerr()'s result is     *
  418. *       valid after calling this routine.                          *
  419. *     : When the file is finished with, you can use Delete_NIB as "UnRead_NIB".    *
  420. *     : The file will NOT be locked or open after the routine is done.          *
  421. *     : If the file is empty the program will output an error message and abort.   *
  422. *     : Assume all registers destroyed.                          *
  423. ***************************************************************************************
  424. NRead_NIB
  425.     Move.l    a1,-(SP)        Preserve pointer to filename.
  426.     Bsr    Create_NIB        Create a new NIB for this file.
  427. ;;;;;;;    (Errors handled automatically)
  428.     Move.l    (SP)+,a1        Restore pointer to filename.
  429. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
  430.     Move.l    Active_NIB(a5),a0    -._ Put pointer to filename
  431.     Move.l    a1,NIB_NameAdrs(a0)    -'  into the NIB structure.
  432. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
  433.     Moveq    #ACCESS_READ,d2        -._ Lock() the file
  434.     Bsr    Lock_NIB        -'  with READ mode.
  435.     Tst.l    d0            -._ If it failed,
  436.     Beq.s    NRead_NIB_Failure    -'  abort the routine.
  437. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
  438.     Bsr    Examine_NIB        Allocate and fill-in the FileInfoBlock
  439. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
  440.     Move.l    Active_NIB(a5),a0        -.
  441.     Move.l    NIB_FIB(a0),a1             |- Want to allocate enough space to
  442.     Move.l    fib_Size(a1),NIB_MemSize(a0)    -'  load the entire file in to memory.
  443.     Beq_ErrorE    ErrAct_EmptyFile(pc),Active_NIB(a5)
  444. ;;;;;;;    (The Finish routine will delete the NIB, there's no need to worry about it).
  445.     Bsr    Allocate_NIB        Allocate the memory for the file.
  446. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
  447.     Move.l    #MODE_OLDFILE,d2    -._ Open the file
  448.     Bsr    Open_NIB        -'  (must already exit).
  449.     Tst.l    d0            -._ If it failed,
  450.     Beq.s    NRead_NIB_Failure    -'  abort the routine.
  451. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
  452.     Bsr    UnLock_NIB        Don't need the lock anymore, so UnLock file.
  453. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
  454.     Move.l    Active_NIB(a5),a0
  455.     Move.l    NIB_Handle(a0),d1    Handle to read from,
  456.     Move.l    NIB_MemAdrs(a0),d2    Memory to read into,
  457.     Move.l    NIB_MemSize(a0),d3    Amount to read (filesize and memory size).
  458.     N_CallDOS    Read        Read the file into memory.
  459.     Cmpi.l    #-1,d0            (Read returns -1 for error!)
  460.     Beq.s    NRead_NIB_Failure
  461. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
  462.     Bsr    Close_NIB        Close the file.
  463. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
  464.     Moveq    #1,d0            Indicate success.
  465.     RTS
  466. ;-------------------------------------------------------------------------------------;
  467. NRead_NIB_Failure
  468.     Move.l    Active_NIB(a5),a0    Put filename into FakeNIB automatically.
  469.     Move.l    NIB_NameAdrs(a0),NIB_NameAdrs+FakeNIB(a5)
  470.     Bsr    Delete_NIB        Delete the NIB.
  471.     Moveq    #0,d0            Indicate failure.
  472.     RTS
  473. ;-------------------------------------------------------------------------------------;
  474. ErrAct_Read
  475.     Dc.b    "Could not read ",0
  476. ErrAct_EmptyFile
  477.     Dc.b    "File is empty: ",0
  478.     Even
  479.     ENDC
  480.